/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package grafox.Domain;

import grafox.Interface.ActionOnTerminate;
import grafox.Interface.ActionOnVisited;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author admindev
 */
public class VerticeX extends ObjectX {

    protected List<ArestaX> arestasAdj;
    private GrafoX grafo;

    public GrafoX getGrafo() {
        return grafo;
    }

    public void setGrafo(GrafoX grafo) {
        this.grafo = grafo;
    }

    public List<ArestaX> getArestasAdj() {
        return arestasAdj;
    }

    public List<VerticeX> getAdjacentes() {
        List<VerticeX> adjs = new LinkedList<>();
        for (ArestaX aresta : arestasAdj) {
            adjs.add(aresta.destino);
        }
        return adjs;
    }

    public void addAdjacente(ArestaX aresta) {
        aresta.setOrigem(this);
        this.arestasAdj.add(aresta);

    }

    public VerticeX(long id, String nome) {
        super(id, nome);
        arestasAdj = new LinkedList<>();

    }

    public VerticeX(String nome) {
        super(nome);
        arestasAdj = new LinkedList<>();
    }

    public void visit() {

        for (Object object : propriedades) {
            if (object instanceof ActionOnVisited) {
                ((ActionOnVisited) object).execute(this);
            }
        }
    }

    public void terminate() {

        for (Object object : propriedades) {
            if (object instanceof ActionOnTerminate) {
                ((ActionOnTerminate) object).execute(this);
            }
        }
    }
    
    @Override
    public boolean equals(Object o)
    {
        if(o.getClass() != VerticeX.class) return false;
        return ((VerticeX)o).getId() == this.id;
    }
    
    public double pesoAresta(VerticeX vertice)
    {
        for(ArestaX a : this.arestasAdj)
            if(a.vaiPara(vertice))
                return a.getPeso();
        return 0;
    }
}
